import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { fileURLToPath } from "url";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  // base: process.env.NODE_ENV === "production" ? "./" : "/",
  server: {
    proxy: {
      "/mobileApi": {
        target: "https://www.aichunwan.com/index.php/api/index",
        // target: "http://120.55.170.90/index.php/api/index",
        ws: true,
        credentials: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/mobileApi/, "")
      },
      "/front-api": {
        target: "https://www.aichunwan.com/front-api/",
        ws: true,
        credentials: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/front-api/, "")
      }
    }
  },
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "src/icons/svg")], // icon存放的目录
      symbolId: "icon-[name]",
      inject: "body-last", // 插入位置
      customDomId: "__svg__icons__dom__" //svg id
    })
  ],
  resolve: {
    alias: [
      {
        find: "@",
        replacement: fileURLToPath(new URL("./src", import.meta.url)),
      },
      {
        find: "@assets",
        replacement: fileURLToPath(new URL("./src/assets", import.meta.url)),
      },
    ],
  },
});
